SWEP.ViewModelFlip = false
SWEP.Category = "Weapon of doom";
SWEP.Author = "Deathslycer";
SWEP.Contact = "deathslycer@gmail.com";
SWEP.Purpose = "just eat it";
SWEP.Instructions = "fire and die";
SWEP.PrintName = "doomer";
SWEP.Slot = 2;
SWEP.SlotPos = 3;
SWEP.DrawCrosshair = true;
SWEP.DrawAmmo = true;
SWEP.ViewModel = "models/weapons/v_crossbow.mdl";
SWEP.WorldModel = "models/weapons/w_crossbow.mdl";
SWEP.ViewModelFOV = 10;
SWEP.ReloadSound = "weapon/shotgun-reload.wav";
SWEP.HoldType = crossbow
SWEP.Spawnable = true;
SWEP.AdminSpawnable = false;
SWEP.Weight = 10;
SWEP.AutoSwitchTo = true;
SWEP.AutoSwitchFrom = true;
SWEP.FiresUnderwater = false;

SWEP.Primary.Zap = false;
SWEP.Primary.ZapRadius = 150;
SWEP.Primary.ZapDamage = 3000;
SWEP.Primary.RPG = false
SWEP.Primary.RPGType = ""
SWEP.Primary.Sound = ""
SWEP.Primary.Tracer = 1;
SWEP.Primary.Automatic = true;
SWEP.Primary.Force = 5;
SWEP.Primary.FireFromHip = false;
SWEP.Primary.Weld = false;
SWEP.Primary.Ammo = "pistol;
SWEP.Primary.ExplosionShot = false;
SWEP.Primary.BulletShot = true;
SWEP.Primary.ModelShot = false;
SWEP.Primary.BreakAll = true;
SWEP.Primary.Ignite = true;
SWEP.Primary.ClipSize = 999;
SWEP.Primary.DefaultClip = 999999;
SWEP.Primary.Recoil = 0.7;
SWEP.Primary.Damage = 12;
SWEP.Primary.NumberofShots = 1;
SWEP.Primary.Spread = 0,5;
SWEP.Primary.Delay = 0.5;
SWEP.Primary.Model = "odels/promps_c17/FurnitureChair001a.mdl";
SWEP.Primary.ExplosionSound = "weapon/mortar/mortar_explode2.wav";
SWEP.Primary.ExplosionSoundDistance = 400;
SWEP.Primary.ExplosionSize = 175;
SWEP.Primary.TakeAmmo = 12;

SWEP.Secondary.RPG = false
SWEP.Secondary.RPGType = "bazooka_round"
SWEP.Secondary.Sound = "weapons/mortar/mortar_fire2.wav"
SWEP.Secondary.Tracer = 1;
SWEP.Secondary.Force = 10;
SWEP.Secondary.Automatic = false;
SWEP.Secondary.FireFromHip = false;
SWEP.Secondary.Weld = false;
SWEP.Secondary.ExplosionShot = false;
SWEP.Secondary.BulletShot = false;
SWEP.Secondary.ModelShot = false;
SWEP.Secondary.BreakAll = false;
SWEP.Secondary.Zap = false;
SWEP.Secondary.ZapRadius = 150;
SWEP.Secondary.ZapDamage = 3000;
SWEP.Secondary.Ignite = false;
SWEP.Secondary.Recoil = 0.7;
SWEP.Secondary.Spread = 0.1;
SWEP.Secondary.Delay = 0.1;
SWEP.Secondary.Automatic = false;
SWEP.Secondary.Sound = "weapons/pistol/pistol_fire2.wav";
SWEP.Secondary.TakeAmmo = 1;
SWEP.Secondary.Model = "models/props_c17/Chair001a.mdl";
SWEP.Secondary.ExplosionSound = "weapon_AWP.Single";
SWEP.Secondary.ExplosionSoundDistance = 400;
SWEP.Secondary.ExplosionSize = 175;

function SWEP:Initialize()
    util.PrecacheSound(self.Primary.Sound);
    util.PrecacheSound(self.Secondary.Sound);
    if ( SERVER ) then
       self:SetWeaponHoldType( self.HoldType );
   end
end

function SWEP:PrimaryAttack()
   if ( !self:CanPrimaryAttack() ) then return end

//Default stuff, normally used in any condition.
   local tr = self.Owner:GetEyeTrace();
   self.Weapon:EmitSound ( self.Primary.Sound );
   self:ShootEffects();
   self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay );
   self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay );   self:TakePrimaryAmmo(self.Primary.TakeAmmo);
   local rnda = -self.Primary.Recoil;
   local rndb = self.Primary.Recoil * math.random(-1, 1);
   self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) );

//The attack mode, can vary from the user settings
    if ( self.Primary.ModelShot ) then
    if (!SERVER) then return end;
    local ent = ents.Create ("prop_physics");
    ent:SetModel ( self.Primary.Model );
    if ( self.Primary.FireFromHip ) then
        ent:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 32));
    else
        ent:SetPos (tr.HitPos + self.Owner:GetAimVector() * -16);
    end
    ent:SetAngles (self.Owner:EyeAngles());
    ent:Spawn();
    local phys = ent:GetPhysicsObject();
    local shot_length = tr.HitPos:Length();
    if ( self.Primary.Weld ) then
        local weld = constraint.Weld( tr.Entity, ent, tr.PhysicsBone, 0, 0 );
    end
    phys:ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() * math.pow (shot_length, 3));
    cleanup.Add (self.Owner, "props", ent);
    undo.Create ("Thrown model");
    undo.AddEntity (ent);
    undo.SetPlayer (self.Owner);
    undo.Finish();
end    if ( self.Primary.BulletShot ) then
        local bullet = {};
        bullet.Num = self.Primary.NumberofShots;
        bullet.Src = self.Owner:GetShootPos();
        bullet.Dir = self.Owner:GetAimVector();
        bullet.Spread = Vector( self.Primary.Spread * 0.1 , self.Primary.Spread * 0.1, 0);
        bullet.Tracer = self.Primary.Tracer;
        bullet.Force = self.Primary.Force;
        bullet.Damage = self.Primary.Damage;
        bullet.AmmoType = self.Primary.Ammo;
        self.Owner:FireBullets( bullet );
    end
   if ( self.Primary.ExplosionShot ) then
       local explode = ents.Create( "env_explosion" );
       explode:SetPos( tr.HitPos );
       explode:SetOwner( self.Owner );
       explode:Spawn();
       explode:SetKeyValue( "iMagnitude", self.Primary.ExplosionSize );
       explode:Fire( "Explode", 0, 0 );
       explode:EmitSound( self.Primary.ExplosionSound, self.Primary.ExplosionSoundDistance, self.Primary.ExplosionSoundDistance );
    end
    if ( self.Primary.BreakAll ) then
        if( tr.Entity:IsValid() and tr.Entity:GetClass() == "prop_physics" ) then
            constraint.RemoveAll( tr.Entity );
            local physobject = tr.Entity:GetPhysicsObject();
            physobject:EnableMotion( false );
            physobject:SetVelocity( self.Owner:GetAimVector() * 2 );
        end
    end
if ( self.Primary.Zap ) then
   local vaporize = ents.Create ( "point_hurt" )
   vaporize:SetKeyValue ( "DamageRadius", self.Primary.ZapRadius )
   vaporize:SetKeyValue ( "Damage" , self.Primary.ZapDamage )
   vaporize:SetKeyValue ( "DamageDelay", 0 )
   vaporize:SetKeyValue ( "DamageType" ,"67108864" )
   vaporize:SetPos ( tr.HitPos )
   vaporize:Fire ( "TurnOn" , "", 0 )
   vaporize:Fire ( "TurnOff" , "", 0.5 )
end
if ( self.Primary.RPG ) then
    local shotpos = self.Owner:GetShootPos()
    shotpos = shotpos + self.Owner:GetForward() * 0
    shotpos = shotpos + self.Owner:GetRight() * 10
    shotpos = shotpos + self.Owner:GetUp() * -6
    local rocket = ents.Create("hl2_rocket")
    if (ValidEntity(rocket)) then
        rocket:SetPos(shotpos)
        rocket:SetOwner(self.Owner)
     rocket:Spawn()
    rocket.Owner = self.Owner
local TF2Rocket = ents.Create("prop_dynamic")
    if (ValidEntity(TF2Rocket)) then
    TF2Rocket:SetPos(shotpos)
    TF2Rocket:SetModel( "models/weapons/w_missile.mdl" )
    TF2Rocket:Spawn()
   TF2Rocket:SetParent(rocket)
end

    local b = ents.Create( "info_target" )
    if (ValidEntity(b)) then
    b:SetPos( self.Owner:GetEyeTrace( ).HitPos + Vector(0,0,0))
    b:Spawn( )
    rocket:PointAtEntity( b )
    b:Remove( )
end
end
end
    if ( self.Primary.Ignite ) then
        if (!tr.Entity) then return false end
        if (!tr.Entity:IsValid() ) then return false end
        if (tr.Entity:IsPlayer()) then return false end
        if (tr.Entity:IsWorld()) then return false end
        if ( CLIENT ) then return false end
        local Time = math.random(20);
        tr.Entity:Extinguish();
        tr.Entity:Ignite( Time, 0 );
    end

end

function SWEP:SecondaryAttack()
   if ( !self:CanPrimaryAttack() ) then return end

//Default stuff, normally used in any condition.
   local tr = self.Owner:GetEyeTrace();
   self.Weapon:EmitSound ( self.Secondary.Sound );
   self:ShootEffects();
   self.Weapon:SetNextPrimaryFire( CurTime() + self.Secondary.Delay );
   self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay );
   self:TakePrimaryAmmo(self.Secondary.TakeAmmo);
   local rnda = -self.Secondary.Recoil;
   local rndb = self.Secondary.Recoil * math.random(-1, 1);
   self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) );

//The attack mode, can vary from the user settings
if ( self.Secondary.ModelShot ) then
    if (!SERVER) then return end
    local ent = ents.Create ("prop_physics");
    ent:SetModel ( self.Secondary.Model );
    if ( self.Secondary.FireFromHip ) then
        ent:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 32));
    else
        ent:SetPos (tr.HitPos + self.Owner:GetAimVector() * -16);
    end
    ent:SetAngles (self.Owner:EyeAngles());
    ent:Spawn();
    local phys = ent:GetPhysicsObject();
    local shot_length = tr.HitPos:Length();
    if ( self.Secondary.Weld ) then
        local weld = constraint.Weld( tr.Entity, ent, tr.PhysicsBone, 0, 0 );
    end
    phys:ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() * math.pow (shot_length, 3));
    cleanup.Add (self.Owner, "props", ent);
    undo.Create ("Thrown model");
    undo.AddEntity (ent);
    undo.SetPlayer (self.Owner);
    undo.Finish();
end     if (self.Secondary.BulletShot ) then
   local bullet = {};
       bullet.Num = self.Secondary.NumberofShots;
       bullet.Src = self.Owner:GetShootPos();
       bullet.Dir = self.Owner:GetAimVector();
       bullet.Spread = Vector( self.Secondary.Spread * 0.1 , self.Secondary.Spread * 0.1, 0);
       bullet.Tracer = self.Secondary.Tracer;
       bullet.Force = self.Secondary.Force;
       bullet.Damage = self.Secondary.Damage;
       bullet.AmmoType = self.Primary.Ammo;
   self.Owner:FireBullets( bullet );
end
if ( self.Secondary.Zap ) then
   local vaporize = ents.Create ( "point_hurt" )
   vaporize:SetKeyValue ( "DamageRadius", self.Secondary.ZapRadius )
   vaporize:SetKeyValue ( "Damage" , self.Secondary.ZapDamage )
   vaporize:SetKeyValue ( "DamageDelay", 0 )
   vaporize:SetKeyValue ( "DamageType" ,"67108864" )
   vaporize:SetPos ( tr.HitPos )
   vaporize:Fire ( "TurnOn" , "", 0 )
   vaporize:Fire ( "TurnOff" , "", 0.5 )
end
if ( self.Secondary.ExplosionShot ) then
   local explode = ents.Create( "env_explosion" );
   explode:SetPos( tr.HitPos );
   explode:SetOwner( self.Owner );
   explode:Spawn();
   explode:SetKeyValue( "iMagnitude", self.Secondary.ExplosionSize );
   explode:Fire( "Explode", 0, 0 );
   explode:EmitSound( self.Secondary.ExplosionSound, self.Secondary.ExplosionSoundDistance, self.Secondary.ExplosionSoundDistance );
end
   if ( self.Secondary.BreakAll ) then
       if( tr.Entity:IsValid() and tr.Entity:GetClass() == "prop_physics" ) then
           constraint.RemoveAll( tr.Entity );
           local physobject = tr.Entity:GetPhysicsObject();
           physobject:EnableMotion( false );
           physobject:SetVelocity( self.Owner:GetAimVector() * 2 );
       end
   end
    if ( self.Secondary.RPG ) then
    local shotpos = self.Owner:GetShootPos()
    shotpos = shotpos + self.Owner:GetForward() * 0
    shotpos = shotpos + self.Owner:GetRight() * 10
    shotpos = shotpos + self.Owner:GetUp() * -6
    local rocket = ents.Create("hl2_rocket")
    if (ValidEntity(rocket)) then
        rocket:SetPos(shotpos)
        rocket:SetOwner(self.Owner)
     rocket:Spawn()
    rocket.Owner = self.Owner
local TF2Rocket = ents.Create("prop_dynamic")
    if (ValidEntity(TF2Rocket)) then
    TF2Rocket:SetPos(shotpos)
    TF2Rocket:SetModel( "models/weapons/w_missile.mdl" )
    TF2Rocket:Spawn()
   TF2Rocket:SetParent(rocket)
end

    local b = ents.Create( "info_target" )
    if (ValidEntity(b)) then
    b:SetPos( self.Owner:GetEyeTrace( ).HitPos + Vector(0,0,0))
    b:Spawn( )
    rocket:PointAtEntity( b )
    b:Remove( )
end
end
end
if ( self.Secondary.Ignite ) then
    if (!tr.Entity) then return false end
        if (!tr.Entity:IsValid() ) then return false end
        if (tr.Entity:IsPlayer()) then return false end
        if (tr.Entity:IsWorld()) then return false end
        if ( CLIENT ) then return false end
        local Time = math.random(20);
        tr.Entity:Extinguish();
        tr.Entity:Ignite( Time, 0 );    end
end

function SWEP:Think()
end

function SWEP:Reload()
   self.Weapon:DefaultReload(ACT_VM_RELOAD);
   return false
end

function SWEP:Deploy()
   self.Weapon:SendWeaponAnim(ACT_VM_DRAW);
   return false
end

function SWEP:Holster()
   return false
end

function SWEP:OnRemove()
end

function SWEP:OnRestore()
end

function SWEP:Precache()
end

function SWEP:OwnerChanged()
end
